<div class="nav-sub w1180">
	<ul class="zoom">
		<li><a class="on" href="/crm/banner/index">界面管理</a></li>
	</ul>
</div>
	<script type="text/javascript" src="/js/lrz.bundle.js"></script>
	<form enctype="multipart/form-data" action="/crm/banner/save" method="post" name="form1" id="form1" >
	<div class="main-ct w1180">
<!-- 		<a href="javascript:;" class="btn-cs btn-blue btn-fillet mt10">返 回</a> -->
		<h2 class="tit-border">平台主页</h2>
		<div class="form-info form-kv mt20">
			<dl>
				<dt>轮播图：<br>(750*320)&nbsp;&nbsp;</dt>
				<dd id="ban" class="goods-list">
				<?php if(count($this->indexBanner)>0):?>
					<?php foreach ($this->indexBanner as $keyBan=>$Banner):?>
					<div class="img-line">
						<input id="banId_<?php echo $keyBan+1;?>" name="banId_<?php echo $keyBan+1;?>" type="hidden" value="<?php echo $Banner['banner_id'];?>">
    					<div class="goods-img goods-img-add">
    						<div class="g-img-ct">
            					<img id="banImg_<?php echo $keyBan+1;?>" name="banImg_<?php echo $keyBan+1;?>" src="<?php echo $Banner['image'];?>">
            					<input id="banFile_<?php echo $keyBan+1;?>" name="banFile_<?php echo $keyBan+1;?>" type="file" capture="camera" accept="image/*">
        					</div>
        					<a id="banLink_<?php echo $keyBan+1;?>" href="javascript:delePic(1,<?php echo $keyBan+1;?>)" class="btn-del"></a>
    					</div>
    					<input id="banTitle_<?php echo $keyBan+1;?>" name="banTitle_<?php echo $keyBan+1;?>" type="text" class="txt" placeholder="介绍内容（选填）" maxlength="30" value="<?php echo $Banner['title'];?>">
    					<input id="banUrl_<?php echo $keyBan+1;?>" name="banUrl_<?php echo $keyBan+1;?>" type="text" class="txt txt-mm" placeholder="链接地址URL" value="<?php echo $Banner['url'];?>">
					</div>
					<?php endforeach;?>
					<?php if(count($this->indexBanner)<2):?>
					<div class="img-line">
						<input id="banId_2" name="banId_2" type="hidden" value="">
    					<div class="goods-img goods-img-add">
    						<div class="g-img-ct">
        						<img id="banImg_2" name="banImg_2" src="/images/ico/ico-add.png">
        						<input id="banFile_2" name="banFile_2" type="file" capture="camera" accept="image/*">
        					</div>
        					<a id="banLink_2" href="javascript:delePic(1,2)" class="btn-del" style="display:none"></a>
    					</div>
    					<input id="banTitle_2" name="banTitle_2" type="text" class="txt" placeholder="介绍内容（选填）" maxlength="30">
    					<input id="banUrl_2" name="banUrl_2" type="text" class="txt txt-mm" placeholder="链接地址URL">
					</div>
					<?php endif;?>
				<?php else:?>
					<div class="img-line">
						<input id="banId_1" name="banId_1" type="hidden" value="">
    					<div class="goods-img goods-img-add">
    						<div class="g-img-ct">
            					<img id="banImg_1" name="banImg_1" src="/images/ico/ico-add.png">
            					<input id="banFile_1" name="banFile_1" type="file" capture="camera" accept="image/*">
        					</div>
        					<a id="banLink_1" href="javascript:delePic(1,1)" class="btn-del" style="display:none"></a>
    					</div>
    					<input id="banTitle_1" name="banTitle_1" type="text" class="txt" placeholder="介绍内容（选填）" maxlength="30">
    					<input id="banUrl_1" name="banUrl_1" type="text" class="txt txt-mm" placeholder="链接地址URL">
					</div>
					<div class="img-line">
						<input id="banId_2" name="banId_2" type="hidden" value="">
    					<div class="goods-img goods-img-add">
    						<div class="g-img-ct">
        						<img id="banImg_2" name="banImg_2" src="/images/ico/ico-add.png">
        						<input id="banFile_2" name="banFile_2" type="file" capture="camera" accept="image/*">
        					</div>
        					<a id="banLink_2" href="javascript:delePic(1,2)" class="btn-del" style="display:none"></a>
    					</div>
    					<input id="banTitle_2" name="banTitle_2" type="text" class="txt" placeholder="介绍内容（选填）" maxlength="30">
    					<input id="banUrl_2" name="banUrl_2" type="text" class="txt txt-mm" placeholder="链接地址URL">
					</div>
				<?php endif;?>
				</dd>
			</dl>
			<div class="mb10">
				<a id="ban_more" class="btn-cs btn-l btn-fillet btn-blue ml170 btn-add-more" href="javascript:addBanner(1);">+添加更多</a>
			</div>
			<dl>
				<dt>商品／类目展示：</dt>
				<dd class="goods-list">
					<?php for($i=1;$i<6;$i++):?>
					<div class="img-line img-line-ss <?php if($i%2==1):?>mr80<?php endif;?>">
						<input id="typeId_<?php echo $i;?>" name="typeId_<?php echo $i;?>" type="hidden" value="<?php echo isset($this->indexType[$i-1])?$this->indexType[$i-1]['type_id']:'';?>">
						<!-- 上传成功显示-->
						<div class="goods-img goods-img-add">
							<div class="g-img-ct">
							    <img id="typeImg_<?php echo $i;?>" name="typeImg_<?php echo $i;?>" src="<?php echo isset($this->indexType[$i-1])?$this->indexType[$i-1]['type_thumb_image']:'/images/ico/ico-add.png';?>">
            					<input id="typeFile_<?php echo $i;?>" name="typeFile_<?php echo $i;?>" type="file" capture="camera" accept="image/*">
							</div>
							<a id="typeLink_<?php echo $i;?>" href="javascript:delePic(3,<?php echo $i;?>)" class="btn-del" <?php if(!isset($this->indexType[$i-1])):?>style="display:none"<?php endif;?>></a>
						</div>
						<!-- 默认显示-->
						<input id="typeName_<?php echo $i;?>" name="typeName_<?php echo $i;?>" type="text" class="txt txt-ss" placeholder="名 称" maxlength="4" value="<?php echo isset($this->indexType[$i-1])?$this->indexType[$i-1]['type_name']:'';?>">
						<input id="typeLink_<?php echo $i;?>" name="typeLink_<?php echo $i;?>" type="text" class="txt txt-mm" placeholder="链接地址URL" value="<?php echo isset($this->indexType[$i-1])?$this->indexType[$i-1]['type_link']:'';?>">
					</div>
					<?php endfor;?>
				</dd>
			</dl>
		</div>

		<h2 class="tit-border tit-border-orange">溯源系统</h2>
		<div class="form-info form-kv mt20">
			<dl>
				<dt>轮播图：<br>(750*320)&nbsp;&nbsp;</dt>
				<dd id="mat"  class="goods-list">
				<?php if(count($this->materialBanner)>0):?>
					<?php foreach ($this->materialBanner as $keyMat=>$matBanner):?>
					<div class="img-line">
						<input id="matId_<?php echo $keyMat+1;?>" name="matId_<?php echo $keyMat+1;?>" type="hidden" value="<?php echo $matBanner['banner_id'];?>">
    					<div class="goods-img goods-img-add">
    						<div class="g-img-ct">
            					<img id="matImg_<?php echo $keyMat+1;?>" name="matImg_<?php echo $keyMat+1;?>" src="<?php echo $matBanner['image'];?>">
            					<input id="matFile_<?php echo $keyMat+1;?>" name="matFile_<?php echo $keyMat+1;?>" type="file" capture="camera" accept="image/*">
        					</div>
        					<a id="matLink_<?php echo $keyMat+1;?>" href="javascript:delePic(2,<?php echo $keyMat+1;?>)" class="btn-del"></a>
    					</div>
    					<input id="matTitle_<?php echo $keyMat+1;?>" name="matTitle_<?php echo $keyMat+1;?>" type="text" class="txt" placeholder="介绍内容（选填）" maxlength="30" value="<?php echo $matBanner['title'];?>">
    					<input id="matUrl_<?php echo $keyMat+1;?>" name="matUrl_<?php echo $keyMat+1;?>" type="text" class="txt txt-mm" placeholder="链接地址URL" value="<?php echo $matBanner['url'];?>">
					</div>
					<?php endforeach;?>
					<?php if(count($this->materialBanner)<2):?>
					<div class="img-line">
						<input id="matId_2" name="matId_2" type="hidden" value="">
    					<div class="goods-img goods-img-add">
    						<div class="g-img-ct">
        						<img id="matImg_2" name="matImg_2" src="/images/ico/ico-add.png">
        						<input id="matFile_2" name="matFile_2" type="file" capture="camera" accept="image/*">
        					</div>
        					<a id="matLink_2" href="javascript:delePic(2,2)" class="btn-del" style="display:none"></a>
    					</div>
    					<input id="matTitle_2" name="matTitle_2" type="text" class="txt" placeholder="介绍内容（选填）" maxlength="30">
    					<input id="matUrl_2" name="matUrl_2" type="text" class="txt txt-mm" placeholder="链接地址URL">
					</div>
					<?php endif;?>
				<?php else:?>
					<div class="img-line">
						<input id="matId_1" name="matId_1" type="hidden" value="">
    					<div class="goods-img goods-img-add">
    						<div class="g-img-ct">
            					<img id="matImg_1" name="matImg_1" src="/images/ico/ico-add.png">
            					<input id="matFile_1" name="matFile_1" type="file" capture="camera" accept="image/*">
        					</div>
        					<a id="matLink_1" href="javascript:delePic(2,1)" class="btn-del" style="display:none"></a>
    					</div>
    					<input id="matTitle_1" name="matTitle_1" type="text" class="txt" placeholder="介绍内容（选填）" maxlength="30">
    					<input id="matUrl_1" name="matUrl_1" type="text" class="txt txt-mm" placeholder="链接地址URL">
					</div>
					<div class="img-line">
						<input id="matId_2" name="matId_2" type="hidden" value="">
    					<div class="goods-img goods-img-add">
    						<div class="g-img-ct">
        						<img id="matImg_2" name="matImg_2" src="/images/ico/ico-add.png">
        						<input id="matFile_2" name="matFile_2" type="file" capture="camera" accept="image/*">
        					</div>
        					<a id="matLink_2" href="javascript:delePic(2,2)" class="btn-del" style="display:none"></a>
    					</div>
    					<input id="matTitle_2" name="matTitle_2" type="text" class="txt" placeholder="介绍内容（选填）" maxlength="30">
    					<input id="matUrl_2" name="matUrl_2" type="text" class="txt txt-mm" placeholder="链接地址URL">
					</div>
				<?php endif;?>
				</dd>
			</dl>
			<div class="mb10">
				<a id="mat_more" class="btn-cs btn-l btn-fillet btn-blue ml170 btn-add-more" href="javascript:addBanner(2);">+添加更多</a>
			</div>
		</div>
		<p class="mt30 txt-center"><a class="input-cs btn-fillet btn-green" href="javascript:formSub();">确定</a></p>
	</div>
	</form>
<script>
// 'indexBanner'=> $indexBanner,
// 'materialBanner'=> $materialBanner,
// 'indexType' => $indexType,
	function formSub(){
// 		for(var i=1;i<9;i++){
			
// 		}


//		 var formData = new FormData($( "#form1" )[0]);  
// 	     $.ajax({  
// 	          url: 'http://localhost:8080/cfJAX_RS/rest/file/upload' ,  
// 	          type: 'POST',  
// 	          data: formData,  
// 	          async: false,  
// 	          cache: false,  
// 	          contentType: false,  
// 	          processData: false,  
// 	          success: function (returndata) {  
// 	              alert(returndata);  
// 	          },  
// 	          error: function (returndata) {  
// 	              alert(returndata);  
// 	          }  
// 	     });  
		$("#form1").submit();
	}
	function delePic(type,id){
		if(type==1){
	    	$('#banImg_'+id).attr("src","/images/ico/ico-add.png");
	    	$('#banLink_'+id).hide();
	    	$('#banFile_'+id).val('');
		}else if(type==2){
	    	$('#matImg_'+id).attr("src","/images/ico/ico-add.png");
	    	$('#matLink_'+id).hide();
	    	$('#matFile_'+id).val('');
		}else{
	    	$('#typeImg_'+id).attr("src","/images/ico/ico-add.png");
	    	$('#typeLink_'+id).hide();
	    	$('#typeFile_'+id).val('');
		}
	}
    
    $(function(){
        //$("input[type='file']").live('change', function(){
        $(document).on("change","input[type='file']",function(){
         var o=this;
    	 lrz(this.files[0])
    		.then(function (rst) {
    			//console.log(rst);
                // 把处理的好的图片给用户看
    			$(o).prev('img').attr("src",rst.base64);
    			$(o).parents('div').next('a').show();
    		})
    		.catch (function (err) {
    			loadCommonPop("图片错误！");
    		})
    		.always(function () {
    
    		});
    });
    });

    var indBanCon = <?php echo (count($this->indexBanner)>2)?count($this->indexBanner):2;?>;
    var matBanCon = <?php echo (count($this->materialBanner)>2)?count($this->materialBanner):2;?>;
	
	function addBanner(type){
		var html='';
		if(type==1){
			indBanCon = indBanCon + 1;
			var id=""+indBanCon;
			html += '<div class="img-line">';
			html += '<input id="banId_'+id+'" name="banId_'+id+'" type="hidden" value="">';
			html += '<div class="goods-img goods-img-add">';
			html += '	<div class="g-img-ct">';
			html += '		<img id="banImg_'+id+'" name="banImg_'+id+'" src="/images/ico/ico-add.png">';
			html += '		<input id="banFile_'+id+'" name="banFile_'+id+'" type="file" capture="camera" accept="image/*">';
			html += '	</div>';
			html += '	<a id="banLink_'+id+'" href="javascript:delePic(1,'+id+')" class="btn-del" style="display:none"></a>';
			html += '</div>';
			html += '<input id="banTitle_'+id+'" name="banTitle_'+id+'" type="text" class="txt" placeholder="介绍内容（选填）" maxlength="30">&nbsp;';
			html += '<input id="banUrl_'+id+'" name="banUrl_'+id+'" type="text" class="txt txt-mm" placeholder="链接地址URL">';
			html += '</div>';
				
			$("#ban").append(html);
			if(indBanCon >=8) $("#ban_more").hide();
			
		}else{
			matBanCon = matBanCon + 1;
			var id=""+matBanCon;
			html += '<div class="img-line">';
			html += '<input id="matId_'+id+'" name="matId_'+id+'" type="hidden" value="">';
			html += '<div class="goods-img goods-img-add">';
			html += '	<div class="g-img-ct">';
			html += '		<img id="matImg_'+id+'" name="matImg_'+id+'" src="/images/ico/ico-add.png">';
			html += '		<input id="matFile_'+id+'" name="matFile_'+id+'" type="file" capture="camera" accept="image/*">';
			html += '	</div>';
			html += '	<a id="matLink_'+id+'" href="javascript:delePic(2,'+id+')" class="btn-del" style="display:none"></a>';
			html += '</div>';
			html += '<input id="matTitle_'+id+'" name="matTitle_'+id+'" type="text" class="txt" placeholder="介绍内容（选填）" maxlength="30">&nbsp;';
			html += '<input id="matUrl_'+id+'" name="matUrl_'+id+'" type="text" class="txt txt-mm" placeholder="链接地址URL">';
			html += '</div>';
			
			$("#mat").append(html);
			if(matBanCon >=8) $("#mat_more").hide();
			
		}
	}
</script>
